var gulp = require('gulp'),
uglify = require("gulp-uglify"),
rename=require("gulp-rename"),
amdOptimize = require("amd-optimize"),
concat = require('gulp-concat'),
cssmin = require('gulp-minify-css'),
htmlmin = require('gulp-htmlmin'),
livereload = require('gulp-livereload'),
concatCss = require('gulp-concat-css'),
plumber = require('gulp-plumber'),
jshint = require('gulp-jshint'),
Map = require("map-stream");
gulp.task('testConcat', function () {
    gulp.src('pc/src/js/*.js')
    .pipe(plumber())
    .pipe(concat('main.js'))//合并后的文件名
    .pipe(uglify())
    .pipe(gulp.dest('pc/js'));
});
gulp.task('testConcatApp', function () {
    gulp.src('app/src/js/*.js')
    .pipe(plumber())
    .pipe(concat('main.js'))//合并后的文件名
    .pipe(uglify())
    .pipe(gulp.dest('app/js'));
});
/* gulp.task('minify-js', function () {
    gulp.src(['pc/src/js/*.js','!pc/src/js/*.min.js']) // 要压缩的js文件
    .pipe(uglify())  //使用uglify进行压缩,更多配置请参考：
    .pipe(rename({ extname: '.min.js' }))
    .pipe(gulp.dest('pc/js/'));//压缩后的路径
 });*/
gulp.task('concatCss', function () {
  return gulp.src('pc/src/css/*.css')
    .pipe(plumber())
    .pipe(concatCss("bundle.css"))
    .pipe(cssmin())
    .pipe(gulp.dest('pc/css'));
});
gulp.task('concatCssApp', function () {
  return gulp.src('app/src/css/*.css')
    .pipe(plumber())
    .pipe(concatCss("bundle.css"))
    .pipe(cssmin())
    .pipe(gulp.dest('app/css'));
});
/*gulp.task('testCssmin', function () {
    gulp.src(['pc/src/css/*.css','!pc/src/css/*.min.css'])
        .pipe(cssmin())
        .pipe(rename({ extname: '.min.css' }))
        .pipe(gulp.dest('pc/css'));
});*/
gulp.task('testHtmlmin', function () {
    var options = {
        removeComments: true,//清除HTML注释
        collapseWhitespace: true,//压缩HTML
        collapseBooleanAttributes: true,//省略布尔属性的值 <input checked="true"/> ==> <input />
        removeEmptyAttributes: true,//删除所有空格作属性值 <input id="" /> ==> <input />
        removeScriptTypeAttributes: true,//删除<script>的type="text/javascript"
        removeStyleLinkTypeAttributes: true,//删除<style>和<link>的type="text/css"
        minifyJS: true,//压缩页面JS
        minifyCSS: true//压缩页面CSS
    };
    gulp.src('pc/src/tpl/*.html')
        .pipe(plumber())
        .pipe(htmlmin(options))
        .pipe(gulp.dest('pc/tpl'));
}); 
gulp.task('testHtmlminApp', function () {
    var options = {
        removeComments: true,//清除HTML注释
        collapseWhitespace: true,//压缩HTML
        collapseBooleanAttributes: true,//省略布尔属性的值 <input checked="true"/> ==> <input />
        removeEmptyAttributes: true,//删除所有空格作属性值 <input id="" /> ==> <input />
        removeScriptTypeAttributes: true,//删除<script>的type="text/javascript"
        removeStyleLinkTypeAttributes: true,//删除<style>和<link>的type="text/css"
        minifyJS: true,//压缩页面JS
        minifyCSS: true//压缩页面CSS
    };
    gulp.src('app/src/tpl/*.html')
        .pipe(plumber())
        .pipe(htmlmin(options))
        .pipe(gulp.dest('app/tpl'));
}); 
gulp.task('jshint', function () {  
    gulp.src('pc/src/js/*.js') 
        .pipe(jshint())  
        .pipe(jshint.reporter("jshint-stylish")); // 输出检查结果  
});
gulp.task('jshintApp', function () {  
    gulp.src('app/src/js/*.js') 
        .pipe(jshint())  
        .pipe(jshint.reporter("jshint-stylish")); // 输出检查结果  
});
gulp.task('default',[],function() {
/*	livereload.listen();*/
    gulp.watch('pc/src/js/*.js',['jshint']);
    gulp.watch('pc/src/js/*.js',['testConcat']);
	gulp.watch('pc/src/css/*.css',['concatCss']);
	gulp.watch('pc/src/tpl/*.html',['testHtmlmin']);
	gulp.watch('app/src/tpl/*.html',['testHtmlminApp']);
	gulp.watch('app/src/js/*.js',['jshintApp']);
    gulp.watch('app/src/js/*.js',['testConcatApp']);
	gulp.watch('app/src/css/*.css',['concatCssApp']);

});